package cn.gailvlun.gll.presentation.wish

import android.graphics.drawable.Drawable
import android.text.Html
import android.text.Spanned
import cn.gailvlun.gll.Constants
import cn.gailvlun.gll.R
import cn.gailvlun.gll.net.wish.Wish
import cn.gailvlun.gll.presentation.base.App
import cn.gailvlun.gll.util.IsEmpty
import org.joda.time.DateTime


object Util {

    private val sResources = App.getInstance().resources
    @JvmStatic
    fun getAge(birthday: String?): String {
        return if (IsEmpty.string(birthday)) {
            ""
        } else {
            val split = birthday?.split("-".toRegex())?.dropLastWhile { it.isEmpty() }?.toTypedArray()
            val birthdayYear = Integer.valueOf(split!![0].trim { it <= ' ' })!!
            val dateTime = DateTime()
            val thisYear = dateTime.year
            (thisYear - birthdayYear).toString()
        }
    }

    @JvmStatic
    fun getValidity(dayNum: Int): Spanned {
        return Html.fromHtml(App.getInstance().resources.getString(R.string.wish_accepted_validity, dayNum))
    }

    @JvmStatic
    fun getExhaustion(): Spanned {
        return Html.fromHtml(App.getInstance().getString(R.string.wish_accepter_exhaustion))
    }

    @JvmStatic
    fun getRefuseWaring(): Spanned {
        return Html.fromHtml(App.getInstance().getString(R.string.wish_refuse_waring))
    }

    @JvmStatic
    fun getStatus(item: Wish): Drawable {
        
        return when (item.status) {
            1 -> sResources.getDrawable(R.drawable.bg_wish_receiving)
            2 -> sResources.getDrawable(R.drawable.bg_wish_realizing)
            3 -> sResources.getDrawable(R.drawable.bg_wish_realized)
            else -> sResources.getDrawable(R.drawable.bg_wish_receiving)
        }
    }

    @JvmStatic
    fun getScoreDrawable(score: Int): Drawable {
        
        return when (score) {
            Constants.SATISFACTORY -> sResources.getDrawable(R.drawable.icon_wish_satisfy_normal)
            Constants.NORMAL -> sResources.getDrawable(R.drawable.icon_wish_normal_normal)
            Constants.BORING -> sResources.getDrawable(R.drawable.icon_wish_boring_normal)
            Constants.PERFUNCTORY -> sResources.getDrawable(R.drawable.icon_wish_perfunctory_normal)
            else -> sResources.getDrawable(R.drawable.icon_wish_satisfy_normal)
        }
    }

    @JvmStatic
    fun getScoreText(score: Int): String {
        return when (score) {
            Constants.SATISFACTORY -> sResources.getString(R.string.wish_score_satisfactory)
            Constants.NORMAL -> sResources.getString(R.string.wish_score_normal)
            Constants.BORING -> sResources.getString(R.string.wish_score_boring)
            Constants.PERFUNCTORY -> sResources.getString(R.string.wish_score_perfunctory)
            else -> sResources.getString(R.string.wish_score_satisfactory)
        }
    }
}